package obj;

import org.newdawn.slick.Graphics;

import play.Things;

import util.Rect;
import util.Settings;

/**
 * Projectile class.
 * @author VincentLy
 */
public class Projectile extends Rect{

	private int dmg;
	private int xvel;
	private int yvel;	
	private int dir;
	private int uses;
	private boolean trans;
	private Sprite owner;
	
	public Projectile(float x,float y,int xv, int yv,int u,boolean b,Sprite s) {
		super(x,y,20,10,5);
		xvel = xv;
		yvel = yv;
		if(s == Things.player)
			dmg = 2;
		else
			dmg = 25;
		if(xv>0)
			dir = 1;
		else
			dir = -1;
		uses = u;
		trans = b;
		owner = s;
	}
	
	/**
	 * @return projectile's owner
	 * @author VincentLy
	 */
	public Sprite owner(){return owner;}
	
	/**
	 * @return transparency
	 * @author VincentLy
	 */
	public boolean trans(){return trans;}
	
	/**
	 * @param u - number of uses
	 * @author VincentLy
	 */
	public void setUses(int u){uses = u;}
	
	/**
	 * @return bullet uses
	 * @author VincentLy
	 */
	public int uses(){return uses;}
	
	/**
	 * @return direction
	 * @author VincentLy
	 */
	public int dir(){return dir;}
	
	/**
	 * Updates the projectile location.
	 * @author VincentLy
	 */
	public void update(){move(x()+xvel,y()-yvel);}
	
	/**
	 * @return projectile damage
	 * @author VincentLy
	 */
	public int dmg(){return dmg;}
	
	/**
	 * Draws the bullet.
	 * @author VincentLy
	 */
	public void draw(Graphics g){
		if(owner() instanceof Player){
			if(dir == 1)
				Settings.bullet.draw(left(),top());
			else
				Settings.backbullet.draw(left(),top());
		}	
		else
			g.draw(this);
	}
}